import sys
from PySide2 import QtCore, QtWidgets
# from QtWidgets import  QApplication,QFileDialog
# from QtCore import  SIGNAL,QRect,QObject,SLOT
import ui_ApplicationWindow
from PySide2.QtCore import Slot
from dlgabout import dlgabout
from dlgstandard import dlgstandard
from dlgOpenSample import dlgOpenSample
from dlgtp import dlgtp
from dbdata import DBdata
import myglobal
from PySide2.QtCharts import *
from numpy import arange,sin,cos
class ApplicationWindow(QtWidgets.QMainWindow):
    ui=ui_ApplicationWindow.Ui_MaMainWindowClass();
    def __init__(self, parent=None):
        QtWidgets.QMainWindow.__init__(self, parent)
        self.ui.setupUi(self)
        myglobal.tp1.dataArrive.connect(self.tp_dataArrive)
        
        self.curve1 =  QtCharts.QLineSeries()
        # self.x = arange(0, 10.0, 10.0/27)
        # self.y1 = sin(self.x)
        # for i in range(len(self.x)):
        #     self.curve1.append(self.x[i], self.y1[i])

        self.chart = QtCharts.QChart()
        self.chart.addSeries(self.curve1)
        self.axis_x = QtCharts.QValueAxis()
        self.axis_x.setLabelFormat('%.1f')
        self.axis_x.setTitleText('X')
        self.axis_x.setTickCount(11)
        self.axis_x.setMinorTickCount(4)
        self.axis_y = QtCharts.QValueAxis()
        self.axis_y.setLabelFormat('%.1f')
        self.axis_y.setTitleText('Y')
        self.chart.addAxis(self.axis_x,QtCore.Qt.AlignBottom)
        self.chart.addAxis(self.axis_y, QtCore.Qt.AlignLeft)
        self.curve1.attachAxis(self.axis_x)
        self.curve1.attachAxis(self.axis_y)
        self.ui.graphicsView.setChart(self.chart)
        self.i=0
    def tp_dataArrive(self,value):
        self.ui.lineEdit_weight.setText(str(value))
        self.i+=1
        print(self.i,value)
        self.curve1.append(self.i,value)
    def handled1(self):
        pass
    @Slot()
    def on_actionStandards_triggered(self):
        l=dlgstandard(self);
        l.exec();
    @Slot()
    def on_actionOpenSample_triggered(self):
        l=dlgOpenSample(self);
        l.exec();
        pass
    @Slot()
    def on_actionTP_triggered(self):
        print("on_tp_triggered");
        d=dlgtp()
        d.exec()
    @Slot()
    def on_actionAbout_triggered(self):
        print("on_actionAbout_triggered");
        d=dlgabout()
        d.exec()
    def chkLcClick(self):
        print("on_actionAbout_triggered");
        d=dlgabout()
        d.exec()        
    def chkLsClick(self):
        print("on_actionAbout_triggered");
        d=dlgabout()
        d.exec()        
    def chkHcClick(self):
        print("on_actionAbout_triggered");
        d=dlgabout()
        d.exec()        
    def chkHsClick(self):
        print("on_actionAbout_triggered");
        d=dlgabout()
        d.exec()        
    @Slot()
    def on_actionExit_triggered(self):
        self.close()    
if __name__ == "__main__":
    a = QtWidgets.QApplication(sys.argv)
    a.lastWindowClosed.connect(a.quit)
    w = ApplicationWindow()
    w.show()
    a.exec()